﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
namespace GUI
{
    public partial class FrmTraCuuBan : Form
    {
        public FrmTraCuuBan()
        {
            InitializeComponent();
        }
        // button tra cuu ban
        private void bnttracuu_Click(object sender, EventArgs e)
        {
            //kiem tra xem da chon tieu chi tra cuu chua
            if (rdtrangthai.Checked == false && rdthoigiandat.Checked == false)
            {
                MessageBox.Show("Bạn Chưa Chọn Tiêu Chí Tra Cứu", "Thông Báo");
                return;
            }
            if (rdtrangthai.Checked == true)
            {
                if (cmbtrangthai.Text == "")
                {
                    MessageBox.Show("Bạn Chựa Chọn Trạng Thái Bàn", "Thông Báo");
                    return;
                }
                if (cmbtrangthai.SelectedIndex < 0)
                {
                    return;
                }
                BanBUS bs = new BanBUS();
                String trangthai = this.cmbtrangthai.SelectedItem.ToString();
                List<BanDTO> ds = bs.laydanhsachbantheotrangthai(trangthai);
                GridViewdsban.Rows.Clear();
                for (int i = 0; i < ds.Count; i++)
                {
                    GridViewdsban.Rows.Add(i + 1, ds[i].MaBan, ds[i].TrangThai, ds[i].ThoiGianDat, ds[i].KhuVuc);
                }
            }
            else if (rdthoigiandat.Checked == true)
            {
                BanBUS bs = new BanBUS();
                string timetu = dateptu.Value.ToString("yyyy-MM-dd HH:mm:ss");
                string timeden = datepden.Value.ToString("yyyy-MM-dd HH:mm:ss");
                List<BanDTO> ds = bs.LayDSBanTheoThoiGianDat(timetu, timeden);
                GridViewdsban.Rows.Clear();
                for (int i = 0; i < ds.Count; i++)
                {
                    GridViewdsban.Rows.Add(i + 1, ds[i].MaBan, ds[i].TrangThai, ds[i].ThoiGianDat, ds[i].KhuVuc);
                }
            }
        }
        //button thoat
        private void FrmTraCuuBan_FormClosed(object sender, FormClosedEventArgs e)
        {
            Program.frm_manhinhchinh.sub_mn_tracuuban.Checked = false;
        }

    }
}
